<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>社保项目</title>
<script type="text/javascript" src="../static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="../static/easyui/jedate.min.js"></script>
<script type="text/javascript" src="../static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/easyui/themes/metro-orange/easyui.css">
<link rel="stylesheet" href="../static/easyui/themes/metro-red/window.css">
<link rel="stylesheet" href="../static/ttt/css/SocialSecurity.css?<%=Math.random()%>">
<style type="text/css">

</style>
</head>
<body>
<script type="text/javascript">
var scsyids=0;
function sesur_table(){
	$('#SocialSecuritytable').datagrid({    
		url:'scsytable', //数据源地址
	   	columns:[[    
	   	 	{field:'SCSYID',width:213,title:'社保id',align:'center'},    
	   	   {field:'SCSYNAME',width:213,title:'社保名称',align:'center'},    
	       {field:'SCSYTYPE',width:213,title:'社保类型',align:'center'},
	       {field:'TAXID',width:213,title:'社保纳税',align:'center',hidden:true},
	       {field:'dates2',width:213,formatter:secu_formatter,title:'操作',align:'center'} 
	      
	    ]],
	    //toolbar:'#aaaatb',
	    pagination:true,
	    pageNumber:1,
	    pageSize:5,
	    pageList:[5,10,15] 

	}); 
}
$(function(){
	sesur_table();
	$("#addSocialSecurityName").click(function(){
		$("#SocialSecuritywin").window("open");
	}) 
	//关闭窗口
	$("#SocialSecurity_quxiao").click(function(){
		$("#SocialSecuritywin").window("close");
	})
	//新增社保项目，提交
	$("#SocialSecurity_tijiao").click(function(){
		
		var scsyname=$("#SocialSecurity_name").val();
		var scsytype=$("#SocialSecurity_leixing").val();
		if(scsyname!=""&&scsytype!=""){
			$.ajax({
				type:"post",
				url:"addSecurity",
				data:{"scsyname":scsyname,"scsytype":scsytype},
				success: function(data){
					/*添加成功，刷新表格数据  */
					sesur_table();
				}
			})
			
			//添加成功后，关闭页面
			$("#SocialSecuritywin").window("close")
		}else{
			$.messager.show({
				title:'信息提示',
				msg: '请输入社保项目或社保类型',
				timeout:1500,  //1秒后消失
				showType:'slide',//弹出的方式。类似ppt里的图片弹出方式
				//弹出框的样式。居中显示
				style:{
					
				}
			});
		}
	})
	//点击确定社保纳税新增
	
		$("#shebaonashui_queding").click(function(){
			var rows=$("#SocialSecuritytable").datagrid('getChecked');
			var scsyid=rows[0].scsyid;
			var taxgd=parseFloat($("#gudingjishu").val());
			var taxmax=parseFloat($("#zuigaojishu").val()); 
			var taxmin=parseFloat($("#zuidijishu").val()); 
			var taxgr=parseFloat($("#gerennashui").val());
			var taxgs=parseFloat($("#gongsinashui").val());
			if(taxgd.toString() =="NaN"){
				alert("固定基数只能为数字型/请填写固定基数！")
			}else if(taxmax.toString() =="NaN"){
				alert("最大基数只能为数字型请填写最大基数！")
			}else if(taxmin.toString() =="NaN"){
				alert("最小基数只能为数字型请填写最小基数！")
			}else if(taxgr.toString() =="NaN"){
				alert("个人纳税只能为数字型请填写个人纳税！")
			}else if(taxgs.toString() =="NaN"){
				alert("公司纳税只能为数字型请填写公司纳税！")
			}else if(taxgr>0.2){
				alert("个人纳税不能超过20%")
			}else if(taxgs>0.3){
				alert("公司纳税不能超过30%")
			}else{
				$.ajax({
					type:"post",
					url:"addTax",
					data:{
						scsyid:scsyids,
						taxgd:$("#gudingjishu").val(),
						taxmax:$("#zuigaojishu").val(),
						taxmin:$("#zuidijishu").val(),
						taxgr:$("#gerennashui").val(),
						taxgs:$("#gongsinashui").val()
					},
					success:function(data){
						$("#shebaonashui_win").window("close");
						sesur_table();
					}
					
				})
			}
			
		})
		//根据社保项目名称查询
		$("#selectSocialSecurityName").click(function(){
			var text=$("#SocialSecurity_text").val();
			if(text!=""){
				alert(11)
				$('#SocialSecuritytable').datagrid({    
					url:'scsytable_name', //数据源地址
					queryParams: {  		
						text:text  		
					},
				   	columns:[[    
				   	 	{field:'SCSYID',width:213,title:'社保id',align:'center'},    
				   	   {field:'SCSYNAME',width:213,title:'社保名称',align:'center'},    
				       {field:'SCSYTYPE',width:213,title:'社保类型',align:'center'},
				       {field:'TAXID',width:213,title:'社保纳税',align:'center',hidden:true},
				       {field:'dates2',width:213,formatter:secu_formatter,title:'操作',align:'center'} 
				      
				    ]],
				    //toolbar:'#aaaatb',
				    pagination:true,
				    pageNumber:1,
				    pageSize:5,
				    pageList:[5,10,15] 

				}); 
				$("#SocialSecurity_text").val("");
			}else if(text==""){
				sesur_table();
			}
		})

})
//在每个操作列里面添加编辑，查看，明细，删除
	function secu_formatter(value, row, index) {
		if(row['TAXID']==""){
			return "<span class='spanclass' onclick='nashui("+row['SCSYID']+")' style='color:red'>添加社保纳税</span>";

		}else if(row['TAXID']!=""){
			return "<span class='spanclass' onclick='nashui("+row['SCSYID']+")' style='color:green'>查看社保纳税</span>";
		}
	} 
	function nashui(value){
	/* 	var rows=$("#SocialSecuritytable").datagrid('getChecked');
		var scsyid=rows[0].scsyid */
		//if(){}
		scsyids=value;
		$.ajax({
			type:"post",
			url:"SelectScsy",
			data:{scsyid:value},
			success:function(data){
				if(data.length!=0){
					$("#gudingjishu").attr("readonly","readonly");
					$("#zuigaojishu").attr("readonly","readonly");
					$("#zuidijishu").attr("readonly","readonly");
					$("#gerennashui").attr("readonly","readonly");
					$("#gongsinashui").attr("readonly","readonly");
					
					$("#gudingjishu").val(data[0].TAXGD);
					$("#zuigaojishu").val(data[0].TAXMAX)
					$("#zuidijishu").val(data[0].TAXMIN);
					$("#gerennashui").val(data[0].TAXGR);
					$("#gongsinashui").val(data[0].TAXGS);
					$("#shebaonashui_queding").hide();
				}else if(data.length==0){
					$("#gudingjishu").removeAttr("readonly");
					$("#zuigaojishu").removeAttr("readonly");
					$("#zuidijishu").removeAttr("readonly");
					$("#gerennashui").removeAttr("readonly");
					$("#gongsinashui").removeAttr("readonly");
					
					$("#gudingjishu").val("");
					$("#zuigaojishu").val("")
					$("#zuidijishu").val("");
					$("#gerennashui").val("");
					$("#gongsinashui").val("");
					$("#shebaonashui_queding").show();
				}
			}
			
		})
		$("#shebaonashui_win").window("open");
		
		
	}
</script>
	<div id="shebaonashui_win" class="easyui-window" title="社保项目纳税" style="width:350px;height:350px"
			data-options="modal:true,resizable: false,draggable:false,closed:true,minimizable:false,maximizable:false,collapsible:false">
			<div style="margin:0px auto;margin-top:15px;width:260px;">
				固定基数（元）：
				<input id="gudingjishu" type="text"style="width:135px;height:25px;margin-left:5px;">
			</div>
			<div style="margin:0px auto;margin-top:15px;width:260px;">
				最高基数（元）：
				<input id="zuigaojishu" type="text"style="width:135px;height:25px;margin-left:5px;">
			</div>
			<div style="margin:0px auto;margin-top:15px;width:260px;">
				最低基数（元）：
				<input id="zuidijishu" type="text"style="width:135px;height:25px;margin-left:5px;">
			</div>
			<div style="margin:0px auto;margin-top:15px;width:260px;">
				个人纳税(*100)：
				<input id="gerennashui" type="text"style="width:135px;height:25px;margin-left:5px;">
			</div>
			<div style="margin:0px auto;margin-top:15px;width:260px;">
				公司纳税(*100)：
				<input id="gongsinashui" type="text" style="width:135px;height:25px;margin-left:5px;">
			</div>
			<button id="shebaonashui_queding"style="margin-left:135px;margin-top:20px;">确定</button>
		</div>
		
		
	<div id="SocialSecuritywin" class="easyui-window" title="社保项目" style="width:420px;height:300px"
		    	data-options="modal:true,resizable: false,draggable:false,closed:true,minimizable:false,maximizable:false,collapsible:false">
		<div  id="span_name">
			<span class="fontstyle">社保名称：</span>
			<input text="text" id="SocialSecurity_name" name="scsyname" class="SocialSecurityClass">
		</div>
		<div id="span_leixing">
			<span class="fontstyle">社保类型：</span>
			<input text="text" id="SocialSecurity_leixing" name="scsytype" class="SocialSecurityClass">
		</div>
		<hr id="SocialSecurityHr">
			<div id="SocialSecurity_box">
				<button id="SocialSecurity_tijiao" class="SocialSecurity" style="margin-right:15px;">
				<img src="../static/tyl/images/go.png">
				提交</button>
				<button id="SocialSecurity_quxiao" class="SocialSecurity" style="margin-right:15px;">
				<img src="../static/tyl/images/cha.png">
				取消</button>
			</div>
	</div>
	<div id="Trainingbox">
			<span id="SocialSecurityname" class="fontstyle">名称：<span><input text="text" id="SocialSecurity_text" class="TrainingPlanName">
			<button id="selectSocialSecurityName" class="SocialSecurity" style="margin-right:15px;">查询</button>
			<button id="addSocialSecurityName" class="SocialSecurity" style="margin-right:15px;">新增</button>
	</div>
	<div class="table_1">
		<table id="SocialSecuritytable" class="easyui-datagrid" style="width:100%;height:260px;" data-options="fitColumns:true,singleSelect: true">
						
		</table>
	</div>
	
	<!-- <div id="aaaatb">
		<a id="add" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true"></a>
		<a id="edit" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"></a>
	</div> -->
</body>
</html>